<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = path + "/resource/extjs/skins/default";
%>
<html>
	<head>
		<jsp:include page="/common.jsp" />
		<!-- include common.jsp -->
		<base />
		<script type="text/javascript">
		var basePath='<%=basePath%>';
		var path='<%=path%>';
		var store_pro_onOrder;
		function deleteUser(id){
			var r=confirm("确定要删除吗");
			if(r==true){
				Ext.Ajax.request({
					url:path+'/picture/deleteUser.do',
					params:{"userId":id},
					success:reload
				});
			}
		};
		function updateUser(userId){
			var form=form_create_user.getForm();
			form.load({
				url:path+'/picture/loadUser.do',
				params:{'userId':userId},
				success:function(){
					
				}
			});
			win_create_user.show();
		}
		function reload(){
			store_pro_onOrder.load({
				callback:function(rec,opt){
				
				}
			});
		};
		 //头部广告
	    var form_create_user = new Ext.form.FormPanel({
	    	frame:true,
	    	border : false,
	    	items : [{
	    		layout:'form',
	    		id:'form_create_user',
	    		//frame:true,
	    		border:false,
	    		width:450,
	    		height:300,
	    		defaultType: 'textfield',
	    		bodyStyle:'padding:10px 5px 0 20px',
	    		defaults: {width: 230},
	    		reader:new Ext.data.JsonReader({
					root:'data',
					successProperty:'success'
				},[
						{name: 'userId',mapping:'userId'},
				        {name: 'userName',mapping:'userName'},
				        {name: 'password',mapping:'password'},
				        {name: 'userSex',mapping:'userSex'},
				        {name: 'phone',mapping:'phone'}
				]),
	    		items: [{
					name:'userId',
					hidden:true
				},{
	    			fieldLabel: '用户名',
	    			name: 'userName',
	    			allowBlank:false
	    		},{
	    			fieldLabel: '密码',
	    			name: 'password',
	    			inputType:'password',
	    			allowBlank:false
	    		},{
	                fieldLabel: '电话',
	                name: 'phone'
	            },{
	            	xtype: 'radiogroup',
		            fieldLabel: '性别',
		            name:'userSex',
		            allowBlank:false,
		            items: [
		                {boxLabel: '男', name: 'userSex', inputValue: 1},
		                {boxLabel: '女', name: 'userSex', inputValue: 0}
		            ]
	       		}]	
	    	}]		
	    });	
	    var win_create_user;
	    var userId;
	   	win_create_user=new Ext.Window({
	    	title:'用户添加',
	    	width:400,
	    	modal:true,
	    	items:[form_create_user],
	    	closeAction:'hide',
	    	plain:true,
	    	frame:true,
	    	buttons:[{
	    		text:'提交',
	    		handler:createUserList
	    	},{
	    		text:'关闭',
	    		handler:function(){
	    			win_create_user.hide();
	    		}
	    	}]	
	    });	
	    //用户添加
	    function createUserList(){
	    	var form=form_create_user.getForm();
	   		form.submit({
	   			url:path+'/picture/createUser.do',
	   			waitMsg:'load...',
	   			success:function(form,action){
	   				reload();
	   				win_create_user.hide();
	   				form_create_user.getForm().reset();
	   				
	   			}	
	   		})		
	    };
	    Ext.onReady(function(){
	    	store_pro_onOrder=new Ext.data.Store({
				proxy: new Ext.data.HttpProxy({
					url:path+'/picture/getAllUser.do'
				}),
				reader: new Ext.data.JsonReader({
					root:'root',
					fields:[
						{name:'userId'},
						{name:'userName'},
						{name:'createDate'},
						{name:'phone'},
						{name:'opt'}
					]
				})
			});
			var grid_pro_onOrder=new Ext.grid.GridPanel({
				//autoHeight:true,
				store:store_pro_onOrder,
				border:false,
				autoScroll:true,
				height:220,
				viewConfig: { forceFit:true},
				columns:[
					{align:'center',dataindex:'userId',hidden:true},
					{header:'用户名',align:'center',dataindex:'userName'},
					{header:'日期',align:'center',dataindex:'createDate'},
					{header:'电话',align:'center',dataindex:'phone'},
					{header:'操作',align:'center',dataindex:'opt',renderer:function(v1,v2,rec){
						return '<a href="javascript:void(0);" onclick="updateUser(\''+rec.data.userId+'\')">修改</a>&nbsp;&nbsp;<a href="javascript:void(0);" onclick="deleteUser(\''+rec.data.userId+'\')">删除</a>'
					}}
				]
			});
			reload();
		    form_upload_left_pic = new Ext.form.FormPanel({
	    		frame:true,
				border : false,
				renderTo:'upload_second_pic',
				id:'form_upload_second_pic',
				//fileUpload:true,
				border:false,
				width:700,
				bodyStyle:'padding:10px 5px 0 20px',
				layout:'fit',
				items: [grid_pro_onOrder],
		            buttons:[{
		            	text:'添加',
		            	id:'upload',
		            	handler:function(){
		            		win_create_user.show();
		            	}
					}]
			});
			
			
		});
		</script>
	</head>
	<body>
		<style>
			body {
			margin: 0;
			padding: 0 0 12px 0;
			font-size: 12px;
			line-height: 22px;
			font-family: "宋体", "Arial Narrow";
			background: #fff;
		}
		</style>
		<div id="upload_second_pic">
		</div>
	</body>
</html>
